﻿using DistributedVisionRunner.Module.Converters;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;

namespace DistributedVisionRunner.Module.Views
{
    /// <summary>
    /// Interaction logic for ImageLayoutSettingDialog.xaml
    /// </summary>
    public partial class ImageLayoutSettingDialog : Window, INotifyPropertyChanged
    {
        private ItemPlacementMethod _selectedPlacement;
        private uint _imageWidth;
        private uint _imageHeight;
        private uint _imagesPerRow;


        public ImageLayoutSettingDialog(ItemPlacementMethod currentPlacement, uint currentImagesPerRow, uint imageWidth, uint imageHeight)
        {
            InitializeComponent();

            SelectedPlacement = currentPlacement;
            ImagesPerRow = currentImagesPerRow;
            ImageWidth = imageWidth;
            ImageHeight = imageHeight;
        }


        public List<PlacementOptionItem> OptionItems => PlacementOptionSelectionConverter.OptionItems;


        public ItemPlacementMethod SelectedPlacement
        {
            get => _selectedPlacement;
            set
            {
                _selectedPlacement = value;
                OnPropertyChanged();
            }
        }

        public uint ImagesPerRow
        {
            get => _imagesPerRow;
            set
            {
                _imagesPerRow = value;
                OnPropertyChanged();
            }
        }

        public uint ImageWidth
        {
            get => _imageWidth;
            set
            {
                _imageWidth = value;
                OnPropertyChanged();
            }
        }

        public uint ImageHeight
        {
            get => _imageHeight;
            set
            {
                _imageHeight = value;
                OnPropertyChanged();
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }


        private void OnOkButtonClicked(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }
    }


    public class PlacementOptionItem
    {
        public string DisplayText { get; set; }


        public ItemPlacementMethod PlacementMethod { get; set; }
    }
}
